﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using log4net;
using System.Web.Configuration;

namespace TheBullysStore.Models.ModuloAdministracion.TipoAreaComun
{
    public class TipoAreaComunDAO
    {
        public static String cadenaDB = WebConfigurationManager.ConnectionStrings["TheBullysStore"].ConnectionString;
        private static ILog log = LogManager.GetLogger(typeof(TipoAreaComunDAO));

        public List<TipoAreaComunBean> Listartipoareacomun(TipoAreaComunBean tipoareacomun)
        {
            SqlConnection sqlCon = null;
            try{
                List<TipoAreaComunBean> listatipoAreaComun = new List<TipoAreaComunBean>();

                sqlCon = new SqlConnection(cadenaDB);

                sqlCon.Open();

                string commandString = "SELECT * FROM tipo_area_comun WHERE estado = 1";

                SqlCommand sqlCmd = new SqlCommand(commandString, sqlCon);

                SqlDataReader dataReader = sqlCmd.ExecuteReader();

                while (dataReader.Read()){
                    TipoAreaComunBean Tipoareacomun = new TipoAreaComunBean();
                    Tipoareacomun.NombreArea = Convert.ToString(dataReader["Nombre_Area"]);
                    Tipoareacomun.Estado = Convert.ToInt32(dataReader["Estado"]);
                    listatipoAreaComun.Add(Tipoareacomun);
                }
                dataReader.Close();

                return listatipoAreaComun;
            }
            catch (Exception ex)
            {
                log.Error("listarTipoAreaComun(EXCEPTION): ", ex);
                throw ex;
            }
            finally {
                sqlCon.Close();
            }
        }                     
    }
}
